package com.arcsinw.bingeveryday;

import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class WallpaperAdapter extends BaseAdapter {

    private ArrayList<Wallpaper> wallpapers;
    private Context context;

    public WallpaperAdapter(Context context, ArrayList<Wallpaper> wallpapers){
        this.context = context;
        this.wallpapers = wallpapers;
    }

    @Override
    public int getCount() {
        return this.wallpapers.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.wallpaper_list_item, viewGroup, false);
        SimpleImageView imageView = (SimpleImageView)view.findViewById(R.id.wallpaper_image);
        TextView textView = (TextView)view.findViewById(R.id.wallpaper_copyright);

        imageView.setImageUriEx(getImageUri(wallpapers.get(i).getUrlBase()));
        textView.setText(wallpapers.get(i).getCopyRight());
        return view;
    }

    public String getImageUri(String baseUrl, String resolution){
         String uriString = String.format("https:///www.bing.com%s_%s.jpg", resolution);
         Log.d("imageUri", uriString);
         return uriString;
    }

    public String getImageUri(String baseUrl){
        String uriString = String.format("https://www.bing.com%s_1080x1920.jpg", baseUrl);

        Log.d("imageUri", uriString);
        return uriString;
    }
}
